<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

//get variables passed from index.php
$classroom_id = mysql_real_escape_string(strip_tags($_GET['id']));
$building_id = mysql_real_escape_string(strip_tags($_GET['bid']));

$get_building_data = mysql_query("SELECT * FROM buildings WHERE id = $building_id");
$building_name = mysql_result($get_building_data,0,'building_name');
$abbreviation = mysql_result($get_building_data,0,'abbreviation');

$get_classroom_data = mysql_query("SELECT * FROM classrooms WHERE id = $classroom_id");
$room_num = mysql_result($get_classroom_data,0,'room_num');
$num_seats = mysql_result($get_classroom_data,0,'num_seats');
$classroom_type_id = mysql_result($get_classroom_data,0,'classroom_type_id');

echo "<p>";
	echo "<a href='index.php?id=$building_id'>&lt;&lt; Back to Classrooms Portal</a><br />";
echo "</p>";
echo "<h1>Edit Classroom in $building_name</h1>";

//counting variable
$i = 0;

//select statement
$query="SELECT * FROM classroom_types";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

echo "<form action='edit_do.php' method='post'>";

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Room Number</b></td>";
		echo "<td>";
		echo "<input type='text' name='room_num' value='$room_num'>";
		echo "</td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Seating Capacity</b></td>";
		echo "<td>";
		echo "<input type='text' name='num_seats' value='$num_seats'>";
		echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
		echo "<td><b>Classroom Type</b></td>";
		echo "<td>";
			echo "<select name='type'>";
				while ($i < $num_rows)
				{
					$type_description=mysql_result($result,$i,"description");
					$type_id=mysql_result($result,$i,"id");
					
					//prepopulate dropdown with current room type
					if ($type_id == $classroom_type_id)
					{
						echo "<option selected='selected' value='$type_id'>$type_description</option>";
					}
					else
					{
						echo "<option value='$type_id'>$type_description</option>";
					}
					
					$i++;
				}
			echo "</select>";
	echo "</tr>";

//end table tag
echo "</table>";

echo "<input type='hidden' name='id' value='$classroom_id'>";
echo "<input type='hidden' name='bid' value='$building_id'>";
echo "<p><input type='submit'></p>";
echo "</form>";


?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>